package com.guet.main.Listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.guet.main.entity.Room;
import com.guet.main.entity.RoomTimeSlice;
import com.guet.main.entity.vo.SliceVo;
import com.guet.main.service.RoomService;
import com.guet.main.service.RoomTimeSliceService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Classname SliceListener
 * @Description TODO
 * @Date 2022/7/31 16:46
 * @Created by csp
 */
@Component
public class SliceListener extends AnalysisEventListener<SliceVo> {
    public RoomTimeSliceService roomTimeSliceService;
    public String roomId;
    public RoomService roomService;

    public SliceListener(RoomTimeSliceService roomTimeSliceService,RoomService roomService,String roomId) {
        this.roomTimeSliceService = roomTimeSliceService;
        this.roomId = roomId;
        this.roomService = roomService;
    }

    public SliceListener() {
    }
    @Override
    public void invoke(SliceVo sliceVo, AnalysisContext analysisContext) {
        RoomTimeSlice roomTimeSlice = new RoomTimeSlice();
        BeanUtils.copyProperties(sliceVo,roomTimeSlice);
        roomTimeSlice.setRoomId(roomId);
        Room room = roomService.getById(roomId);
        roomTimeSlice.setRoomName(room.getName());
        roomTimeSliceService.save(roomTimeSlice);
    }
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
